{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[5 6 7 8]\n",
      "[[ 1  2  3  4]\n",
      " [ 4  5  6  7]\n",
      " [ 7  8  9 10]]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "a = np.array([1,2,3,4])\n",
    "b = np.array([5,6,7,8])\n",
    "c = np.array([[1,2,3,4],[4,5,6,7],[7,8,9,10]])\n",
    "print(b)\n",
    "print(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(4,)\n",
      "(4,)\n",
      "(3, 4)\n"
     ]
    }
   ],
   "source": [
    "print(a.shape)\n",
    "print(b.shape)\n",
    "print(c.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1  2  3]\n",
      " [ 4  4  5]\n",
      " [ 6  7  7]\n",
      " [ 8  9 10]]\n"
     ]
    }
   ],
   "source": [
    "c.shape=4,3\n",
    "print(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(2, 6)\n",
      "[[ 1  2  3  4  4  5]\n",
      " [ 6  7  7  8  9 10]]\n"
     ]
    }
   ],
   "source": [
    "c.shape = 2,-1\n",
    "print(c.shape)\n",
    "print(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2]\n",
      " [3 4]]\n"
     ]
    }
   ],
   "source": [
    "d = a.reshape(2,2)\n",
    "print(d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[  1 100]\n",
      " [  3   4]]\n"
     ]
    }
   ],
   "source": [
    "a[1] = 100\n",
    "print(d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "int64\n"
     ]
    }
   ],
   "source": [
    "print(c.dtype)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1., 2., 3., 4.])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.array([1,2,3,4], dtype=np.float)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1.+0.j, 2.+0.j, 3.+0.j, 4.+0.j])"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.array([1,2,3,4],dtype=np.complex)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "numpy.float64"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.typeDict[\"d\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "numpy.float64"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.typeDict[\"double\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "numpy.float64"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.typeDict[\"float64\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{numpy.bool_,\n",
       " numpy.bytes_,\n",
       " numpy.complex128,\n",
       " numpy.complex256,\n",
       " numpy.complex64,\n",
       " numpy.datetime64,\n",
       " numpy.float128,\n",
       " numpy.float16,\n",
       " numpy.float32,\n",
       " numpy.float64,\n",
       " numpy.int16,\n",
       " numpy.int32,\n",
       " numpy.int64,\n",
       " numpy.int8,\n",
       " numpy.longlong,\n",
       " numpy.object_,\n",
       " numpy.str_,\n",
       " numpy.timedelta64,\n",
       " numpy.uint16,\n",
       " numpy.uint32,\n",
       " numpy.uint64,\n",
       " numpy.uint8,\n",
       " numpy.ulonglong,\n",
       " numpy.void}"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "set(np.typeDict.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1.+0.j, 2.+0.j, 3.+0.j, 4.+0.j], dtype=complex64)"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.array([1,2,3,4],dtype=np.complex64)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9])"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.arange(0,1,0.1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.        , 0.11111111, 0.22222222, 0.33333333, 0.44444444,\n",
       "       0.55555556, 0.66666667, 0.77777778, 0.88888889, 1.        ])"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.linspace(0,1,10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9])"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.linspace(0,1,10,endpoint=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([  1.        ,   3.16227766,  10.        ,  31.6227766 ,\n",
       "       100.        ])"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.logspace(0,2,5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1.        , 1.05946309, 1.12246205, 1.18920712, 1.25992105,\n",
       "       1.33483985, 1.41421356, 1.49830708, 1.58740105, 1.68179283,\n",
       "       1.78179744, 1.88774863])"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.logspace(0,1,12, base=2, endpoint=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[94186324765728,              0,              0],\n",
       "       [             0,              0,              0]])"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.empty((2,3), np.int)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0., 0., 0., 0.])"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.zeros(4, np.float)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/xacrb/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:2: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead\n",
      "  \n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([ 97,  98,  99, 100, 101, 102, 103, 104], dtype=int8)"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = \"abcdefgh\"\n",
    "np.fromstring(s, dtype=np.int8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 97,  98,  99, 100, 101, 102, 103, 104], dtype=int8)"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = b\"abcdefgh\"\n",
    "np.frombuffer(s, dtype=np.int8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([25185, 25699, 26213, 26727], dtype=int16)"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.frombuffer(s, dtype=np.int16)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([8.54088322e+194])"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.frombuffer(s, dtype=np.float)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1., 2., 3., 4., 1., 2., 3., 4., 1., 2.])"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def func(i):\n",
    "    return i%4+1\n",
    "\n",
    "np.fromfunction(func, (10,))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1.  2.  3.  4.  5.  6.  7.  8.  9.]\n",
      " [ 2.  4.  6.  8. 10. 12. 14. 16. 18.]\n",
      " [ 3.  6.  9. 12. 15. 18. 21. 24. 27.]\n",
      " [ 4.  8. 12. 16. 20. 24. 28. 32. 36.]\n",
      " [ 5. 10. 15. 20. 25. 30. 35. 40. 45.]\n",
      " [ 6. 12. 18. 24. 30. 36. 42. 48. 54.]\n",
      " [ 7. 14. 21. 28. 35. 42. 49. 56. 63.]\n",
      " [ 8. 16. 24. 32. 40. 48. 56. 64. 72.]\n",
      " [ 9. 18. 27. 36. 45. 54. 63. 72. 81.]]\n"
     ]
    }
   ],
   "source": [
    "def func2(i, j):\n",
    "    return (i+1) * (j+1)\n",
    "\n",
    "a = np.fromfunction(func2, (9,9))\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 1 2 3 4 5 6 7 8 9]\n"
     ]
    }
   ],
   "source": [
    "a = np.arange(10)\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5\n",
      "[3 4]\n",
      "[0 1 2 3 4]\n",
      "[0 1 2 3 4 5 6 7 8]\n",
      "[  0   1 100 101   4   5   6   7   8   9]\n",
      "[  1 101   5   7]\n",
      "[  9   8   7   6   5   4 101 100   1   0]\n",
      "[  5 101]\n"
     ]
    }
   ],
   "source": [
    "print(a[5])\n",
    "print(a[3:5])\n",
    "print(a[:5])\n",
    "print(a[:-1])\n",
    "a[2:4] = 100,101\n",
    "print(a)\n",
    "print(a[1:-1:2])\n",
    "print(a[::-1])\n",
    "print(a[5:1:-2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[101   4   5   6]\n",
      "[101   4 -10   6]\n",
      "[  0   1 100 101   4 -10   6   7   8   9]\n"
     ]
    }
   ],
   "source": [
    "b = a[3:7]\n",
    "print(b)\n",
    "b[2] = -10\n",
    "print(b)\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[10  9  8  7  6  5  4  3  2]\n",
      "[7 7 9 2]\n",
      "[  7   7 100   2]\n",
      "[10  9  8  7  6  5  4  3  2]\n",
      "[10 -3  8 -1  6 -2  4  3  2]\n",
      "139825484146288\n",
      "139825484146928\n"
     ]
    }
   ],
   "source": [
    "x = np.arange(10, 1, -1)\n",
    "print(x)\n",
    "print(x[[3,3,1,8]])\n",
    "b = x[[3,3,-3,8]]\n",
    "b[2] = 100\n",
    "print(b)\n",
    "print(x)\n",
    "x[[3,5,1]] = -1, -2, -3\n",
    "print(x)\n",
    "print(id(x))\n",
    "print(id(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[7 7 9 2]\n",
      "[[7 7 9 2]\n",
      " [7 7 4 2]]\n",
      "[[7 7 9 2]\n",
      " [7 7 4 2]]\n"
     ]
    }
   ],
   "source": [
    "x = np.arange(10, 1, -1)\n",
    "print(x[np.array([3,3,1,8])])\n",
    "print(x[np.array([[3,3,1,8],[3,3,-3,8]])])\n",
    "print(x[[3,3,1,8,3,3,-3,8]].reshape(2,4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[5 4 3 2 1]\n",
      "[5 3]\n",
      "[5 3]\n",
      "[5 3 2 1]\n",
      "[-1  4 -2 -3  1]\n"
     ]
    }
   ],
   "source": [
    "x = np.arange(5,0,-1)\n",
    "print(x)\n",
    "print(x[np.array([True,False,True,False,False])])\n",
    "print(x[[True,False,True,False,False]])\n",
    "print(x[np.array([True,False,True,True, True])])\n",
    "x[np.array([True,False,True,True, False])] = -1, -2, -3\n",
    "print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0.74167872 0.46581348 0.95863513 0.8617368  0.28651415 0.20723965\n",
      " 0.91999959 0.76841919 0.85541072 0.99120647]\n",
      "[ True False  True  True False False  True  True  True  True]\n",
      "[0.74167872 0.95863513 0.8617368  0.91999959 0.76841919 0.85541072\n",
      " 0.99120647]\n"
     ]
    }
   ],
   "source": [
    "x = np.random.rand(10)\n",
    "print(x)\n",
    "print(x > 0.5)\n",
    "print(x[x>0.5])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
